package org.znxs.znxsframe.init;


import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import org.znxs.znxsframe.constant.MQConstant;

/**
 * 用于创建测试程序用到的交换机和队列【只用在程序启动前执行一次】
 */
public class BIMQInitMain {

    public static void main(String[] args) {
        try {
            // 创建连接
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            // 有密码设置密码
//            factory.setUsername("admin");
//            factory.setPassword("Znxs159357*");
            Connection connection = factory.newConnection();
            // 创建频道
            Channel channel = connection.createChannel();
            channel.exchangeDeclare(MQConstant.EXCHANGE_NAME, "direct");

            // 创建队列，随机分配一个队列名称
            channel.queueDeclare(MQConstant.QUEUE_NAME, true, false, false, null);
            channel.queueBind(MQConstant.QUEUE_NAME, MQConstant.EXCHANGE_NAME, MQConstant.ROUTING_KEY);
        } catch (Exception e) {

        }

    }
}
